﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace MzkUi
{
    public partial class UiProgressBar : UserControl
    {
        private int value = 0; // 默认值
        [Browsable(true), Category("MZK自定义"), Description("设置进度条值"), DefaultValue(0)]
        /// <summary>
        /// 在属性栏可见
        /// </summary>
        public int MzkValue 
        {
            get { return value; }
            set {
                    if (this.value != value)
                    {
                        if (value < 0 || value > 100)
                        {
                            return ;
                        }
                        this.value = value;
                        int width = this.value * (ProgressbarPnl.Size.Width-2) / 100;
                        Progressbar.Size = new Size(width, ProgressbarPnl.Size.Height-1);
                        this.ProgressbarValue.Text = $"{this.value}%";
                    }
                ; }
        }
        [Browsable(true), Category("MZK自定义"), Description("进度条颜色设置"), DefaultValue(typeof(Color), "LightGray")]
        /// <summary>
        /// 进度条颜色设置
        /// </summary>
        public Color MzkBarColor
        {
            get { return Progressbar.BackColor; }
            set { Progressbar.BackColor = value; }
        }
        /// <summary>
        /// 进度值背景颜色设置
        /// </summary>
        [Browsable(true), Category("MZK自定义"), Description("进度值背景颜色设置"), DefaultValue(typeof(Color), "LightGray")]
        public Color MzkBarValueBackgroundColor
        {
            get { return ProgressbarValue.BackColor; }
            set { ProgressbarValue.BackColor = value; }
        }
        /// <summary>
        /// 进度值颜色设置
        /// </summary>
        [Browsable(true), Category("MZK自定义"), Description("进度值颜色设置"), DefaultValue(typeof(Color), "Back")]
        public Color MzkBarValueColor
        {
            get { return ProgressbarValue.ForeColor; }
            set { ProgressbarValue.ForeColor = value; }
        }
        /// <summary>
        /// 是否显示进度值，在进度条后方显示；
        /// </summary>
        [Browsable(true), Category("MZK自定义"), Description("是否显示进度值，在进度条后方显示；"), DefaultValue(true)]
        public bool MzkBarValueVisible
        {
            get { return ProgressbarValue.Visible; }
            set { 
                this.ProgressbarValue.Visible = value;

                int width = this.value * (ProgressbarPnl.Size.Width - 2) / 100;
                Progressbar.Size = new Size(width, ProgressbarPnl.Size.Height - 1);
                this.ProgressbarValue.Text = $"{this.value}%";
            }
        }
        /// <summary>
        /// 设置进度条边框颜色
        /// </summary>
        private Color BorderColor = Color.Black;
        [Browsable(true), Category("MZK自定义"), Description("设置进度条边框颜色"), DefaultValue(typeof(Color), "Black")]
        public Color MzkBarBorderColor
        {
            get { return BorderColor; }
            set 
            { 
                BorderColor = value; 
                RightPanel.BackColor = BorderColor;
                LeftPanel.BackColor = BorderColor;
                TopPanel.BackColor = BorderColor;
                BottomPanel.BackColor = BorderColor;
            }
        }

        public UiProgressBar()
        {
            InitializeComponent();
        }

        private void UiProgressBar_Load(object sender, EventArgs e)
        {
            toolTip.SetToolTip(Progressbar, ProgressbarValue.Text);
            this.ProgressbarValue.Text = $"{this.value}%";
        }

        private void UiProgressBar_SizeChanged(object sender, EventArgs e)
        {
            int width = this.value * (ProgressbarPnl.Size.Width - 2) / 100;
            Progressbar.Size = new Size(width, ProgressbarPnl.Size.Height - 1);
            this.ProgressbarValue.Text = $"{this.value}%";
        }
    }
}
